using System;
using System.Collections;
using XenoGears.Assertions;

namespace Jink.Core.Json.Converters.Shapes.Core
{
    public class JsonSeq : IJsonSeq
    {
        private Func<Type> _telement = () => { throw AssertionHelper.Fail(); };
        private Func<IEnumerable> _elements = () => { throw AssertionHelper.Fail(); };
        private Action<Object> _add = element => { throw AssertionHelper.Fail(); };

        private JsonSeq(){}

        public static JsonSeq ReadOnly(Func<Type> telement, Func<IEnumerable> elements)
        {
            return new JsonSeq{_telement = telement, _elements = elements};
        }

        public static JsonSeq ReadWrite(Func<Type> telement, Func<IEnumerable> elements, Action<Object> add)
        {
            return new JsonSeq{_telement = telement, _elements = elements, _add = add};
        }

        public Type TElement
        {
            get { return _telement(); }
        }

        public IEnumerable Elements
        {
            get { return _elements(); }
        }

        public void Add(Object element)
        {
            _add(element);
        }
    }
}